<template>
  <div>
    <el-table v-loading="loading" :data="noticeList">
      <el-table-column label="序号" prop="order" width="50"></el-table-column>
      <el-table-column label="巡检日期" align="center" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-link type="primary" @click="handleUpdate(scope.row, '记录详情')">{{ scope.row.inspectionDate || '-' }}
          </el-link>
        </template>
      </el-table-column>
      <el-table-column label="巡检时间" align="center" min-width="160" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.inspectionTime || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="巡检人" align="center" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.inspectionUser || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="是否有问题" align="center" min-width="120">
        <template slot-scope="scope">
          <!-- <dict-tag :options="abnormalStatus" :value="scope.row.inspectionStatus" /> -->
          {{ ['无问题', '有问题'][scope.row.problemStatus] }}
        </template>
      </el-table-column>
      <el-table-column label="创建用户" align="center" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.createBy || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="创建日期" align="center" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.createTime || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="修改用户" align="center" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.updateBy || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="修改日期" align="center" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.updateTime || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="220" fixed="right" align="center" class-name="medium-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-hasPermi="['online_xg']" :disabled="!(today <= scope.row.inspectionDate)" size="small"
            type="primary" icon="el-icon-edit" @click="handleDigSelect(scope.row, '修改')">编辑
          </el-button>
          <el-button v-hasPermi="['online_sc']" icon="el-icon-delete" size="small" type="danger"
            @click="handleDelete(scope.row)">删除
          </el-button>
        </template>
      </el-table-column>
      <!-- <div class="card-div"> -->
      <!-- </div> -->
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <template v-if="open">
      <Created :title="title" :rowObj="rowObj"></Created>
    </template>
    <template v-if="openDig">
      <dlgSelect :title="title" :rowObj="rowObj"></dlgSelect>
    </template>
  </div>
</template>

<script>
import { getonlineList, deleteonline } from "@/api/record/index.js";
import { formatDate } from "@/utils/index.js"
export default {
  components: {
    Created: () => import('../form/Created.vue'),
    dlgSelect: () => import('../form/dlgSelect.vue'),
  },
  data () {
    return {
      // 遮罩层
      loading: true,
      openDig: false,
      today: formatDate(new Date, 'yyyy-MM-dd'),
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      dictdatalist: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层表格数据
      noticeList: [],
      rowObj: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: 'id',
        isAsc: 'desc'//倒叙
      },
    };
  },
  created () {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    async getList (value) {
      this.loading = true;
      let params = {
        ...this.queryParams,
        ...value
      }
      //  let data = await getdatalist({ dictType: 'base_unit' })
      //  this.dictdatalist=data.data
      getonlineList(params).then(response => {
        this.noticeList = response.data && response.data.map((item, index) => {
          return {
            ...item,
            order: index + 1
          }
        });
        this.total = response.total;
        this.loading = false;
      });
    },
    handleDigSelect (row, title) {
      this.title = title
      this.rowObj = row
      this.open = true
    },
    handleUpdate (row, title) {
      this.$parent.$parent.$parent.$parent.tabIndex = true
      this.$parent.$parent.$parent.$parent.activeName = '2'
      this.$parent.$parent.$parent.$parent.rowObj = row
      this.$parent.$parent.$parent.$parent.title = title
    },
    /** 启用禁用按钮操作 */
    handleDelete (row) {
      this.$confirm(`是否确认删除该数据？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true;
        deleteonline(row.id).then(res => {
          if (res.code === 200) {
            this.$message.success(res.msg)
            this.getList()
          }
          this.loading = false;
        }).catch(() => { this.loading = false; });
      }).catch(() => { this.loading = false; });
    }
  },
  filters: {
  }
};
</script>
<style lang="scss" scoped>
.red {
  color: red;
}
</style>